home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part1 / 6463 < prev    next >
Encoding:
Text File  |  1996-08-05  |  1.4 KB  |  42 lines

  1. Path: newshost.lanl.gov!tanmoy
  2. From: tanmoy@qcd.lanl.gov (Tanmoy Bhattacharya)
  3. Newsgroups: comp.lang.c
  4. Subject: Re: automatic charrs
  5. Date: 24 Feb 1996 18:24:03 GMT
  6. Organization: Los Alamos National Laboratory
  7. Message-ID: <TANMOY.96Feb24112403@qcd.lanl.gov>
  8. References: <4glp29$dsh@d2.tufts.edu>
  9. NNTP-Posting-Host: qcd.lanl.gov
  10. Mime-Version: 1.0
  11. Content-Type: text
  12. In-reply-to: rdorich@emerald.tufts.edu's message of 24 Feb 1996 01:19:05 GMT
  13.  
  14. In article <4glp29$dsh@d2.tufts.edu>
  15. rdorich@emerald.tufts.edu (Roberto Dorich) writes:
  16.  
  17. RD: Hello,
  18. RD: 
  19. RD: Could someone enlighten me, and tell me why the following program runs
  20. RD: just dandy using Sun's cc (3.0.1), but crashes using gcc (?) ?
  21. RD: 
  22. RD: #include <stdio.h>
  23. RD: char *b() { return "Hello";}
  24. RD:  
  25. RD: main() {
  26. RD:   char *a=b();
  27. RD:  
  28. RD:   a[0]='X';
  29.  
  30. Because you are rtying to modify a string literal. This leads to
  31. undefined behaviour, which is a big no-no.
  32.  
  33. Cheers
  34. Tanmoy
  35. --
  36. tanmoy@qcd.lanl.gov(128.165.23.46) DECNET: BETA::"tanmoy@lanl.gov"(1.218=1242)
  37. Tanmoy Bhattacharya O:T-8(MS B285)LANL,NM87545 H:#9,3000,Trinity Drive,NM87544
  38. Others see <gopher://yaleinfo.yale.edu:7700/00/Internet-People/internet-mail>,
  39. <http://alpha.acast.nova.edu/cgi-bin/inmgq.pl>or<ftp://csd4.csd.uwm.edu/pub/
  40. internetwork-mail-guide>. -- <http://nqcd.lanl.gov/people/tanmoy/tanmoy.html>
  41. fax: 1 (505) 665 3003   voice: 1 (505) 665 4733    [ Home: 1 (505) 662 5596 ]
  42.